package game.worlds;

import hx.utils.ColorUtils;
import hx.geom.ColorTransform;
import hx.display.BitmapData;
import hx.display.Image;
import hx.display.Box;

/**
 * 霸体渲染效果
 */
class StoicDisplay extends Box {
	public var imgaes:Array<Image> = [];

	override function onInit() {
		super.onInit();
		var counts = 4;
		var r = 360 / counts;
		for (i in 0...counts) {
			var img = new Image();
			this.addChild(img);
			imgaes.push(img);
			var angle = r * i;
			var redian = angle * Math.PI / 180;
			img.x = Math.cos(redian) * 1;
			img.y = Math.sin(redian) * 1;
		}
		this.color = 0xffff00;
	}

	public var data(never, set):BitmapData;

	private function set_data(value:BitmapData):BitmapData {
		for (image in imgaes) {
			image.data = value;
		}
		return value;
	}

	/**
	 * 设置霸体的颜色
	 */
	public var color(default, set):UInt;

	private function set_color(value:UInt):UInt {
		if (this.color == value) {
			return value;
		}
		var c = ColorUtils.toShaderColor(value);
		var colorTransform = new ColorTransform(0, 0, 0, 1, 255 * c.r, 255 * c.g, 255 * c.b);
		for (image in imgaes) {
			image.colorTransform = colorTransform;
		}
		return value;
	}
}
